<?php
class FirstContactForm extends Zend_Form
{
    private $picture_path = "";
	private $visitation_datetime = "";
	private $service_datetime = "";
	
    public function __construct($options=array())
    {
        parent::__construct($options);
		
        $this->setName( 'firstContact' );
        $this->setMethod( 'post' );
		$this->setAction( $options['action'] );
		$this->visitation_datetime = $options['visitation_datetime'];	
		$this->service_datetime = $options['service_datetime'];	
        $decorators = array(
            'ViewHelper',
            array('Errors', array('placement'=>'prepend')),
            //array(array('labelBr'=>'HtmlTag'), array('tag'=>'br')),
            array('Label', array('placement'=>'prepend')),
            array( array('outerDiv'=>'HtmlTag'), array('tag'=>'div', 'style'=>'margin-top:8px')),
        );

		$default_loc = $options['default_loc'];

		$f_vis_datetime = new Zend_Form_Element_Text( 'visitation_datetime', 
		array('label'=>"Date/Time:", 'size'=>'30', 'id'=>'visitation_datetime') );
		$f_vis_datetime->setDecorators($decorators);
		
		$f_svc_datetime = new Zend_Form_Element_Text( 'service_datetime', 
		array('label'=>"Date/Time:", 'size'=>'30', 'id'=>'service_datetime') );
		$f_svc_datetime->setDecorators($decorators);
		
		$defaultLoc = $options['default_service_loc'];
		$f_svc_loc = new Zend_Form_Element_Textarea( 'service_loc', 
			array('label'=>"Location:", 'rows'=>'4', 'cols'=>'40', 'value'=>'fred' ) );
		$f_svc_loc->setDecorators($decorators);
		
		
		$f_contact_name = new Zend_Form_Element_Text( 'contact_name', array('label'=>"Name:", 'size'=>'25' ) );
		$f_contact_name->setDecorators($decorators);
		
		$f_contact_address = new Zend_Form_Element_Text( 'contact_address', array('label'=>"Address:", 'size'=>'30') );
		$f_contact_address->setDecorators($decorators);
		
		$f_contact_city = new Zend_Form_Element_Text( 'contact_city', array('label'=>"City:", 'size'=>'30') );
		$f_contact_city->setDecorators($decorators);
		
		$f_contact_state = new Zend_Form_Element_Text( 'contact_state', array('label'=>"State:", 'size'=>'2') );
		$f_contact_state->setDecorators($decorators);
		
		$f_contact_zip = new Zend_Form_Element_Text( 'contact_zip', array('label'=>"Zip:", 'size'=>'10') );
		$f_contact_zip->setDecorators($decorators);
		
		$f_contact_phone = new Zend_Form_Element_Text( 'contact_phone', array('label'=>"Phone:", 'size'=>'16') );
		$f_contact_phone->setDecorators($decorators);
		
		$f_contact_email = new Zend_Form_Element_Text( 'contact_email', array('label'=>"Email:", 'size'=>'40') );
		$f_contact_email->setDecorators($decorators);
		
		$f_secondary_contact_name = new Zend_Form_Element_Text( 'secondary_contact_name', array('label'=>"Name:", 'size'=>'25') );
		$f_secondary_contact_name->setDecorators($decorators);
		
		$f_secondary_contact_address = new Zend_Form_Element_Text( 'secondary_contact_address', array('label'=>"Address:", 'size'=>'30') );
		$f_secondary_contact_address->setDecorators($decorators);
		
		$f_secondary_contact_city = new Zend_Form_Element_Text( 'secondary_contact_city', array('label'=>"City:", 'size'=>'30') );
		$f_secondary_contact_city->setDecorators($decorators);
		
		$f_secondary_contact_state = new Zend_Form_Element_Text( 'secondary_contact_state', array('label'=>"State:", 'size'=>'2') );
		$f_secondary_contact_state->setDecorators($decorators);
		
		$f_secondary_contact_zip = new Zend_Form_Element_Text( 'secondary_contact_zip', array('label'=>"Zip:", 'size'=>'10') );
		$f_secondary_contact_zip->setDecorators($decorators);
		
		$f_secondary_contact_phone = new Zend_Form_Element_Text( 'secondary_contact_phone', array('label'=>"Phone:", 'size'=>'16') );
		$f_secondary_contact_phone->setDecorators($decorators);
		
		$f_secondary_contact_email = new Zend_Form_Element_Text( 'secondary_contact_email', array('label'=>"Email:", 'size'=>'40') );
		$f_secondary_contact_email->setDecorators($decorators);
		
		$f_cemetery_name = new Zend_Form_Element_Text( 'cemetery_name', array('label'=>"Name:", 'size'=>'25') );
		$f_cemetery_name->setDecorators($decorators);
		
		$f_cemetery_address = new Zend_Form_Element_Text( 'cemetery_address', array('label'=>"Address:", 'size'=>'25') );
		$f_cemetery_address->setDecorators($decorators);
		
		$f_cemetery_city = new Zend_Form_Element_Text( 'cemetery_city', array('label'=>"City:", 'size'=>'25') );
		$f_cemetery_city->setDecorators($decorators);
		
		$f_cemetery_state = new Zend_Form_Element_Text( 'cemetery_state', array('label'=>"State:", 'size'=>'2') );
		$f_cemetery_state->setDecorators($decorators);
		
		$f_cemetery_zip = new Zend_Form_Element_Text( 'cemetery_zip', array('label'=>"Zip:", 'size'=>'10') );
		$f_cemetery_zip->setDecorators($decorators);
		
		$f_cemetery_phone = new Zend_Form_Element_Text( 'cemetery_phone', array('label'=>"Phone:", 'size'=>'16') );
		$f_cemetery_phone->setDecorators($decorators);
		
		$f_cemetery_contact_name = new Zend_Form_Element_Text( 'cemetery_contact_name', array('label'=>"Cemetery Contact:", 'size'=>'25') );
		$f_cemetery_contact_name->setDecorators($decorators);
		
		$f_svc_advisor_name = new Zend_Form_Element_Text( 'family_advisor_name', array('label'=>"Service Advisor Name:", 'size'=>'25') );
		$f_svc_advisor_name->setDecorators($decorators);
		
		$f_svc_advisor_phone = new Zend_Form_Element_Text( 'family_advisor_phone', array('label'=>"Service Advisor Phone:", 'size'=>'25') );
		$f_svc_advisor_phone->setDecorators($decorators);

	//	$f_svc_advisor_cell = new Zend_Form_Element_Text( 'family_advisor_cell_phone', array('label'=>"Service Advisor Cell:", 'size'=>'25') );
	//	$f_svc_advisor_cell->setDecorators($decorators);

		$this->addElements( array( 
		$f_vis_datetime,
		$f_svc_datetime,
		$f_svc_loc,
		$f_contact_name,
		$f_contact_address,
		$f_contact_city,
		$f_contact_state,
		$f_contact_zip,
		$f_contact_phone,
		$f_contact_email,
		$f_secondary_contact_name,
		$f_secondary_contact_address,
		$f_secondary_contact_city,
		$f_secondary_contact_state,
		$f_secondary_contact_zip,
		$f_cemetery_name,
		$f_cemetery_address,
		$f_cemetery_city,
		$f_cemetery_state,
		$f_cemetery_zip,
		$f_cemetery_phone,
		$f_cemetery_contact_name,
		$f_svc_advisor_name,
		$f_svc_advisor_phone,
	//	$f_svc_advisor_cell,
		$f_svc_loc,
		$f_contact_name,
		$f_contact_address,
		$f_contact_city,
		$f_contact_state,
		$f_contact_zip,
		$f_contact_phone,
		$f_contact_email,
		$f_secondary_contact_name,
		$f_secondary_contact_address,
		$f_secondary_contact_city,
		$f_secondary_contact_state,
		$f_secondary_contact_zip,
		$f_secondary_contact_phone,
		$f_secondary_contact_email,
		$f_svc_advisor_name,
		$f_svc_advisor_phone,
	//	$f_svc_advisor_cell		
		) );
	}
	
	public function render_with_template( $template_name )
	{
        $template_file_path = APP_DIR."/views/templates/$template_name";
        $template_contents = file_get_contents( $template_file_path );
				
        // str_replace() keywords, adding errors where needed
        $form_elements = $this->getElements();

		$template_contents = str_replace( "{ACTION}", $this->getAction(), $template_contents);
		
		$template_contents = str_replace( "{ENCTYPE}", $this->getEncType(), $template_contents);

        $template_contents = str_replace( "{VISITATION_DATETIME}", $this->visitation_datetime, $template_contents );
        $template_contents = str_replace( "{SERVICE_DATETIME}", $this->service_datetime, $template_contents );
		
        $template_contents = str_replace( "{SERVICE_LOCATION}", "".$form_elements['service_loc'], $template_contents );
        $template_contents = str_replace( "{SERVICE_ADVISOR_NAME}", "".$form_elements['family_advisor_name'], $template_contents );
        $template_contents = str_replace( "{SERVICE_ADVISOR_PHONE}", "".$form_elements['family_advisor_phone'], $template_contents );
  //      $template_contents = str_replace( "{SERVICE_ADVISOR_CELL}", "".$form_elements['family_advisor_cell_phone'], $template_contents );
		
        $template_contents = str_replace( "{CONTACT_NAME}", "".$form_elements['contact_name'], $template_contents );
        $template_contents = str_replace( "{CONTACT_ADDRESS}", "".$form_elements['contact_address'], $template_contents );
        $template_contents = str_replace( "{CONTACT_CITY}", "".$form_elements['contact_city'], $template_contents );
        $template_contents = str_replace( "{CONTACT_STATE}", "".$form_elements['contact_state'], $template_contents );
        $template_contents = str_replace( "{CONTACT_ZIP}", "".$form_elements['contact_zip'], $template_contents );
        $template_contents = str_replace( "{CONTACT_EMAIL}", "".$form_elements['contact_email'], $template_contents );
        $template_contents = str_replace( "{CONTACT_PHONE}", "".$form_elements['contact_phone'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_NAME}", "".$form_elements['secondary_contact_name'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_ADDRESS}", "".$form_elements['secondary_contact_address'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_CITY}", "".$form_elements['secondary_contact_city'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_STATE}", "".$form_elements['secondary_contact_state'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_ZIP}", "".$form_elements['secondary_contact_zip'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_PHONE}", "".$form_elements['secondary_contact_phone'], $template_contents );
        $template_contents = str_replace( "{SECONDARY_CONTACT_EMAIL}", "".$form_elements['secondary_contact_email'], $template_contents );

        $template_contents = str_replace( "{CEMETERY_NAME}", "".$form_elements['cemetery_name'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_ADDRESS}", "".$form_elements['cemetery_address'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_CITY}", "".$form_elements['cemetery_city'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_STATE}", "".$form_elements['cemetery_state'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_ZIP}", "".$form_elements['cemetery_zip'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_PHONE}", "".$form_elements['cemetery_phone'], $template_contents );
        $template_contents = str_replace( "{CEMETERY_CONTACT_NAME}", "".$form_elements['cemetery_contact_name'], $template_contents );

        $template_contents = str_replace( "{SUBMIT_BUTTON}", "".$form_elements['submit'], $template_contents );

        echo $template_contents;
	}
}
?>
